package com.testmanager.testmananger.tools.promotionSign;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.net.URLEncoder;

@Service
@Slf4j
public class SignService {

    public SignResultDto sign(SignDto signDto) throws Exception{
       // signDto.getApplyInfo();
        String jsonStringApplyInfo = signDto.getApplyInfo().toJSONString();
        log.info("jsonStringApplyInfo:{}",jsonStringApplyInfo);
        SignResultDto signResultDto = new SignResultDto();
        signResultDto.setSign(StandardSignUtils.sign(signDto.getAppid(), signDto.getAppSecret()
                , signDto.getMethod(), Codec.strEncodBase64(signDto.getAppSecret(),jsonStringApplyInfo)));
        signResultDto.setApplyInfo(URLEncoder.encode(Codec.strEncodBase64(signDto.getAppSecret(),jsonStringApplyInfo), "UTF-8")) ;
        return signResultDto;
    }

}
